{% extends "base.html" %}

{% block extrahead %}
  {% set title = config.site_name %}
  {% if page and page.meta and page.meta.title %}
    {% set title = title ~ " - " ~ page.meta.title %}
  {% elif page and page.title and not page.is_homepage %}
    {% set title = title ~ " - " ~ page.title %}
  {% endif %}

  {% set url_description = config.site_description %}
  {% if page and page.meta and page.meta.description %}
    {% set url_description = page.meta.description %}
  {% endif %}

  <meta property="og:type" content="website" />
  <meta property="og:title" content="{{ config.site_name }}" />
  <meta property="og:description" content="{{ url_description }}" />
  <meta property="og:url" content="{{ page.canonical_url }}" />
  <meta property="og:image" content="{{ config.site_url }}images/social.png" />
  <meta property="og:image:type" content="image/png" />
  <meta property="og:image:width" content="512" />
  <meta property="og:image:height" content="512" />

  <!-- Twitter Meta Tags -->
  <meta name="twitter:card" content="summary_large_image">
  <meta property="twitter:url" content="{{ page.canonical_url }}">
  <meta name="twitter:title" content="{{ config.site_name }}">
  <meta name="twitter:description" content="{{ url_description }}">
  <meta name="twitter:image" content="{{ config.site_url }}images/social.png">

{% endblock %}


{% block site_meta %}
  <script src="https://telegram.org/js/telegram-web-app.js?35"></script>
    <script type="text/javascript">
      const webapp = window.Telegram.WebApp;
      webapp.disableVerticalSwipes()
      webapp.ready();
      webapp.expand();
      const initData = webapp.initDataUnsafe;
      if (window.location.pathname === "/aiogram-3-guide/" && Object.hasOwn(initData, 'auth_date')) {
        if (initData.start_param) {
          let additionalParam = '';
          switch (initData.start_param) {
            case 'quickstart':
            case 'messages':
            case 'buttons':
            case 'routers':
            case 'special-updates':
            case 'fsm':
            case 'inline-mode':
              additionalParam = initData.start_param;
              break;
            case 'filters':
              additionalParam = 'filters-and-middlewares/#filters';
              break
            case 'middlewares':
              additionalParam = 'filters-and-middlewares/#middlewares';
              break
            case 'magic-filter':
            case 'magic':
              additionalParam = 'filters-and-middlewares/#magic-filters';
              break
            case 'entities':
              additionalParam = 'messages/#message-entities';
              break;
            case 'escaping':
              additionalParam = 'messages/#input-escaping';
              break;
            case 'keep-formatting':
              additionalParam = 'messages/#keep-formatting';
              break
            case 'send-files':
            case 'upload':
              additionalParam = 'messages/#uploading-media';
              break;
            case 'download-files':
            case 'download':
              additionalParam = 'messages/#downloading-media';
              break;
            case 'hide-image':
              additionalParam = 'messages/#bonus';
              break
            case 'callback-factory':
              additionalParam = 'buttons/#callback-factory';
              break
            case 'my-chat-member':
              additionalParam = 'special-updates/#my-chat-member';
              break
            case 'chat-member':
              additionalParam = 'special-updates/#chat-member';
              break
            default:
              additionalParam = '/';
          }
          window.location.href = (`${window.location.origin}${window.location.pathname}${additionalParam}`);
        }
      }
  </script>

  {{ super() }}
{% endblock %}